package com.cinema.util;

import java.util.Scanner;

/**
 * 输入工具类，处理用户输入并进行合法性校验
 */
public class InputUtil {
    private static final Scanner scanner = new Scanner(System.in);

    /**
     * 获取合法的整数输入
     */
    public static int getValidInt() {
        while (true) {
            try {
                String input = scanner.nextLine().trim();
                return Integer.parseInt(input);
            } catch (NumberFormatException e) {
                System.out.print("❌ 请输入有效的整数：");
            }
        }
    }

    /**
     * 获取非空字符串输入
     */
    public static String getValidString() {
        String input;
        do {
            input = scanner.nextLine().trim();
            if (input.isEmpty()) {
                System.out.print("❌ 输入不能为空，请重新输入：");
            }
        } while (input.isEmpty());
        return input;
    }
}

